﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Mortgage
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        Mortgage.Srv.IAgentSrv svc = Mortgage.Srv.SrvFactory.CreateAgentSrv();


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindAgents();
            }
        }

        protected void drpAgdent_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Utility.AgentId.ToString() != drpAgent.SelectedValue)
                RegisterRefreshPage();
            Utility.AgentId = Convert.ToInt32(drpAgent.SelectedValue);

        }

        public void BindAgents()
        {

            if (drpAgent != null)
            {
                drpAgent.DataSource = svc.GetAll();
                drpAgent.DataBind();

                int selAgentId = Utility.AgentId;
                drpAgent.SelectedValue = selAgentId.ToString();



            }
        }

        private void RegisterRefreshPage()
        {
            Page.ClientScript.RegisterStartupScript(typeof(SiteMaster), "refresh", "window.location.reload();", true);
        }
    }
}
